﻿//********************************************************************
// Author:      刘艳明
// Create Date: 2012-09-20
// Description: 
//
// Version:     1.0.0.0
// Change History:
// Date		    Who		      Changes Made
//--------------------------------------------------------------------
// Please Insert the Modiy record here!
//--------------------------------------------------------------------
//********************************************************************


using System;
using System.Collections.Generic;
using System.Data;

using MillerApp.DataAccess;
using MillerApp.DataContract.MillerDB;
using Npgsql;
using NpgsqlTypes;
using MillerApp.CommonLib.DataAccess;

namespace MillerApp.DataAccess.MillerDB
{
	/// <summary>
	/// 这个类提供了对Stockqtreadinfos ()表的数据库操作
	/// </summary>
	public static partial class StockqtreadinfosManager
	{
        private static IDBHelper db = MillerAppDBHelper.CreateDatabase();

		static string insertSQL ="INSERT INTO stockqtreadinfos (notes,userid,tradeday,seccode) VALUES (@notes,@userid,@tradeday,@seccode)";
	
		static string updateSQL ="Update stockqtreadinfos Set notes=@notes,userid=@userid,tradeday=@tradeday,seccode=@seccode Where id=@id";

		static string deleteSQL ="DELETE FROM  stockqtreadinfos  Where id=@id";	
		
		#region codesmith生成的代码
		/// <summary>
		/// 获取StockqtreadinfosEntity实体 
		/// </summary>
		/// <param name="notes">notes</param>
		/// <returns>StockqtreadinfosEntity</returns>
		public static StockqtreadinfosEntity GetStockqtreadinfosEntity(int id)
		{
			string strSQL = "select * from stockqtreadinfos where id=@id";
            IDbDataParameter para_notes = new NpgsqlParameter("id", NpgsqlDbType.Integer);
            para_notes.Value = id;
			IDbDataParameter[] paras=new IDbDataParameter[]{para_notes};
			
			
			StockqtreadinfosEntity entity=new StockqtreadinfosEntity();
			using(System.Data.IDataReader reader=db.ExecuteReader(strSQL,paras))
			{
				if(reader.Read()==false) return null;
				LoadFromReader(reader, ref entity);
				return entity;
			}
		}		
		
		/// <summary>
		/// 更新StockqtreadinfosEntity
		/// </summary>
		/// <param name="entity">Entity</param>	
		public static void UpdateStockqtreadinfos(StockqtreadinfosEntity entity)
		{
			if(entity==null)
			{
				throw new Exception("参数[entity]为[null]！");
			}
			IDbDataParameter[] paras =GenerateParas(entity);		
			db.ExecuteNonQuery(updateSQL,paras);
		}
		
		
				
        
        /// <summary>
		///  插入一条记录
		/// </summary>
		/// <param name="notes">notes</param>		
		public static void InsertStockqtreadinfos(StockqtreadinfosEntity entity)
		{
			if (entity == null)
            {
                throw new Exception("参数[entity]为[null]！");
            }
            IDbDataParameter[] paras = GenerateParas(entity);
            db.ExecuteNonQuery(insertSQL, paras);
		}
		
		/// <summary>
		///  删除一条记录
		/// </summary>
		/// <param name="notes">notes</param>		
        public static void DeleteStockqtreadinfos(int id)
		{
			IDbDataParameter para_notes = new NpgsqlParameter("id", NpgsqlDbType.Integer);
            para_notes.Value = id;
			IDbDataParameter[] paras=new IDbDataParameter[]{para_notes};
			db.ExecuteNonQuery(deleteSQL,paras);
		}

	
		
		/// <summary>
		/// 删除多条记录
		/// </summary>
		/// <param name="notess">notess</param>		
		public static void DeleteStockqtreadinfos(List<int> ids)
		{
			string strSQL = "DELETE FROM  stockqtreadinfos  Where id in ({0}) ";
            string deleteIds = DBHelper.ConvertListToSQLString<int>(ids);
            db.ExecuteNonQuery(string.Format(strSQL, deleteIds),null);
		}
		
		
	
		/// <summary>
		/// 根据分页条件获取Stockqtreadinfos数据集
		/// </summary>
		/// <param name="conditions">条件</param>	
		/// <param name="sortExpression">排序表达式，为空则默认为:notes</param>		
		/// <param name="pageIndex">开始页码：分页查询中的开始页码</param>
		/// <param name="pageSize">页宽：分页查询中的每页的记录数</param>
		/// <param name="recordCount">页宽：分页查询中的每页的记录数</param>		
		/// <returns>数据集(List)</returns>
		public static List<StockqtreadinfosEntity> GetStockqtreadinfossByCond(string conditions,string sortExpression,int pageIndex,int pageSize,out int recordCount)
		{
			string viewName="stockqtreadinfos";
			return db.GetDataListByCond<StockqtreadinfosEntity>
                (viewName, conditions, sortExpression, pageIndex, pageSize, out recordCount, LoadFromReader);
		}
				
		
		/// <summary>
		/// 根据条件获取Stockqtreadinfos数据集
		/// </summary>
		/// <param name="fields">查询的列(如果为空，则表示查询所有列)</param>	
		/// <param name="conditions">条件</param>	
		/// <param name="sortExpression">排序表达式，为空则默认为:notes</param>		
		/// <returns>数据集(DataTable)：<br/></returns>
        public static DataTable GetStockqtreadinfossByCond(string fields, string conditions, string sortExpression)
        {
            string viewName = "stockqtreadinfos";
            return db.GetDataTableByCond(viewName, fields, conditions, sortExpression);
        }
		#region private method
		/// <summary>
        /// 获取StockqtreadinfosEntity实体数据更新参数
        /// </summary>
        /// <param name="entity">CompanyEntity</param>
        /// <returns></returns>
        private static IDbDataParameter[] GenerateParas(StockqtreadinfosEntity entity)
        { 
			IDbDataParameter para_notes = new NpgsqlParameter("notes", NpgsqlDbType.Varchar);
			para_notes.Value = entity.notes;
			
			IDbDataParameter para_userid = new NpgsqlParameter("userid", NpgsqlDbType.Varchar);
			para_userid.Value = entity.userid;
			
			IDbDataParameter para_tradeday = new NpgsqlParameter("tradeday", NpgsqlDbType.Date);
			para_tradeday.Value = entity.tradeday;
			
			IDbDataParameter para_seccode = new NpgsqlParameter("seccode", NpgsqlDbType.Varchar);
			para_seccode.Value = entity.seccode;
			
			IDbDataParameter para_id = new NpgsqlParameter("id", NpgsqlDbType.Integer);
			para_id.Value = entity.id;
			
			return new IDbDataParameter[]{para_notes,para_userid,para_tradeday,para_seccode,para_id};	
        }
		
		/// <summary>
		/// 绑定数据到业务实体
		/// </summary>
		/// <param name="reader">DataReader</param>
		/// <param name="entity">业务实体</param>
		private static void LoadFromReader(IDataReader reader,ref StockqtreadinfosEntity entity)
		{			
			if (reader != null && !reader.IsClosed)
			{
				//entity.Id = reader.GetString(0);
                if(!Convert.IsDBNull(reader["notes"]))entity.notes = reader["notes"].ToString();
                if(!Convert.IsDBNull(reader["userid"]))entity.userid = reader["userid"].ToString();
                if(!Convert.IsDBNull(reader["tradeday"]))entity.tradeday = (DateTime)reader["tradeday"];
                if(!Convert.IsDBNull(reader["seccode"]))entity.seccode = reader["seccode"].ToString();
                if(!Convert.IsDBNull(reader["id"]))entity.id = (int)reader["id"];
			}
			
		}
		#endregion	
		
		#endregion
		
		#region 手工增加的代码
       
        #endregion
	}
}
